﻿using Company.Core.Interfaces;
using Company.Shell.Interfaces;
using Company.Shell.Models;

namespace Company.Shell.Services
{
    class CacheManager : ICacheManager
    {
        public List<CacheEntity> Caches { get; private set; } = new List<CacheEntity>();
        private IConfigManager ConfigManager { get; }
        public CacheManager(IConfigManager configManager)
        {
            ConfigManager = configManager;
            Initialize();
        }

        private void Initialize()
        {
            Caches = ConfigManager.Read<List<CacheEntity>>(Core.Enums.ConfigType.Cache);
            if (Caches == null)
            {
                Caches = new List<CacheEntity>();
                ConfigManager.Write(Core.Enums.ConfigType.Cache, Caches);
            }
        }

        public void Add(CacheEntity entity)
        {
            Caches.Add(entity);
        }

        public void Save()
        {
            ConfigManager.Write(Core.Enums.ConfigType.Cache, Caches);
        }
    }
}
